<?php
// Test of R0910CMS
// created by TLightSky
// time : 20100404

if(!defined("IN_R0910CMS")) {
    exit("Access Denied!");
}

abstract class R_Action_Abstract {
	/*
	 * @ all opended methods was in the array
	 */
	public $_openedMethods = array('dispatch');
	/*
	 * @param defined by the class alone
	 */
	public function __construct() {
		$this->setOpenedAction();
		$this->setCommonClass();
	}
	public function setCommonClass() { }
	public function setOpenedAction() {
		$this->addOpenedMethod(array());
	}
	/*
	 * define a common dispatch do
	 */
    public function dispatch($class,$method,$super=false) {
		//echo($class.' '.$method);
		if($this->checkOpenedMethod($method)) {
			return call_user_method($method,$this);
			//$this->$method();
		} else {
			throw new R_Exception("Class $class does not have opened method : $method!");
		}
	}
	public function checkOpenedMethod($method) {
		return in_array($method,$this->_openedMethods);
	}
	protected function addOpenedMethod($method) {
		if(is_array($method)) {
			foreach($method as $v) {
				$this->addOneOpenedMethod($v);
			}
		} else if(is_string($method)) {
			$this->addOneOpenedMethod($method);
		} else {
			throw new R_Exception_ParamWrong("Methods shoud be a string or array!");
		}
	}
	protected function addOneOpenedMethod($method) {
		if(method_exists($this,$method)) {
			if(!$this->checkOpenedMethod($method)) {
				$this->_openedMethods[] = $method;
			}
		} else {
			throw new R_Exception_ParamWrong("Methods $method do not exists in this Action !");
		}
	}
}
